from datetime import date

def get_subjects(subjects):
    return sorted(subjects)

def sort_tasks(tasks):
    def t(x):
        print x.is_done, x.task.to_date, date.today(), x.task.to_date < date.today()
        if x.task.to_date >= date.today() and not x.is_done:
            return True
        return False
    tasks = filter(t, tasks)
    tasks.sort(cmp=lambda x, x2: x.priority > x2.priority)
    return tasks

def cut_text(text, flen):
    text = unicode(text)
    if len(text) > (flen - 3):
        return text[:flen - 3] + u"..."
    else:
        return text

def check_for_params(params, request):
    for i in params:
        if request.get(i, True):
            return False